commonUtil = {};

$(document).ready(function(){
	if($(".tree a").length > 0 ) tree();
	srch_index();			//개요찾기 레이어
});

function tree(){
	$(".tree a").click(function(e){
		e.preventDefault();
		var idx = $(this).index(".tree a");
		var cls_nm = $(this).attr("class");
		var tr_obj = $(this).parent().parent().parent();
		var tr_obj_cls = $(tr_obj).attr("class");
		var tr_obj_id = $(tr_obj).attr("id");
		var id_val = $(tr_obj).attr("id");

		if(cls_nm.indexOf("minus") > -1){
			cls_nm = cls_nm.replace("minus","plus");
			close_cls = "dp" + (parseInt(tr_obj_cls.replace("dp","")) + 1);
			
			$(".tree_data tr[id^="+tr_obj_id+"]").each(function(index){
				if(tr_obj_cls.replace("dp","") < $(this).attr("class").replace("dp","")){
					if($(this).find(".tree a").length > 0){
						if($(this).find(".tree a").attr("class").indexOf("minus") > -1){
							$(this).find(".tree a").attr("class", $(this).find(".tree a").attr("class").replace("minus","plus"));
						}
					}
					$(this).hide();
				}
			});
		}else{
			cls_nm = cls_nm.replace("plus","minus");
			open_cls = "dp" + (parseInt(tr_obj_cls.replace("dp","")) + 1);
			$(".tree_data tr[id^="+tr_obj_id+"]").each(function(index){
				if($(this).attr("class") == open_cls){
					$(this).show();
				}
			});
		}
		$(this).attr("class", cls_nm);
	});
}

/* 레이어 호출 기본Js */
commonUtil.fnAjaxBaseClass = function(option) {
	$.ajax({
		type: option.type || "POST",
		url: option.url,
		async: option.async || false,
		cache: option.cache || false,
		dataType: option.dataType || "html",
		error: function(XMLHttpRequest, textStatus, errorThrown) {
		},
		success: function(data){
			if(!(option.append==undefined || option.append==null || option.append=="")){ $(option.append).html("").append(data.toString()); }
			if(!(option.callbackFn==undefined || option.callbackFn==null || option.callbackFn=="")) {
				if(!(typeof(option.param)=="object" || option.param==undefined || option.param==null || option.param=="")){
					option.callbackFn();
				} else {
					option.callbackFn(option.param);
				}
			}
		}
	});
};

commonUtil.fnAjaxBase = function(option) {
	$.ajax({
		type: option.type || "POST",
		url: option.url,
		async: option.async || false,
		cache: option.cache || false,
		dataType: option.dataType || "html",
		error: function(XMLHttpRequest, textStatus, errorThrown) {
		},
		success: function(data){
			if(!(option.append==undefined || option.append==null || option.append=="")){ $(option.append).html("").append(data.toString()); }
			if(!(option.callbackFn==undefined || option.callbackFn==null || option.callbackFn=="")) {
				if(!(typeof(option.param)=="object" || option.param==undefined || option.param==null || option.param=="")){
					option.callbackFn();
				} else {
					option.callbackFn(option.param);
				}
			}
		}
	});
};

//href 속성값 가져오기
function get_href(obj){
	var href = obj.attr("href");
	var indexOf = href.indexOf("#");
	href = href.replace(href.substring(0,indexOf),"");
	return href;
}

//offset
function get_offset(obj){
	var offset = obj.offset();
	return [offset.top, offset.left];
}

//레이어 닫기 버튼
function layer_close(){
	$(".layerClose").click(function(e){
		e.preventDefault();
		$(this).parent().parent().parent().parent().hide();
	});
}
